package com.socialin.picsin.camera.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.graphics.PorterDuff;

public class CustomDrawView extends View implements CameraCallBack{
	private Bitmap cameraTakenBitmap;
	private Paint clearModePaint;
	public CustomDrawView(Context context) {
    	super(context);
    	init();
	}

    public CustomDrawView(Context context, AttributeSet attrs) {
        super(context, attrs, android.R.attr.progressBarStyle);
        init();
    }

    public CustomDrawView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
    private void init()
    {
    	bmpDrawPaint.setAntiAlias(true);
    	bmpDrawPaint.setFilterBitmap(true);
    	clearModePaint = new Paint();
    	clearModePaint.setAntiAlias(true);
		PorterDuffXfermode xfer = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
		clearModePaint.setXfermode(xfer);
    }
    private Rect surfaceRect = new Rect(150, 150, 250, 250);
    private Paint bmpDrawPaint = new Paint();
	
	@Override
	protected void onDraw(Canvas canvas) {
		canvas.drawARGB(255, 255, 0, 0);
		
    	if(cameraTakenBitmap!=null)
    	{
    		Log.e("ex", "cameraTakenBitmap!=null");
    		Rect srcRect = new Rect(0, 0, cameraTakenBitmap.getWidth(), cameraTakenBitmap.getHeight());
    		canvas.drawBitmap(cameraTakenBitmap, srcRect, surfaceRect,bmpDrawPaint );
    	}
    	else
    	{
    		
    		canvas.drawRect(surfaceRect, clearModePaint);
    	}
    	
		super.onDraw(canvas);
	}
	public Rect getsurfaceRect()
	{
		return surfaceRect;
	}

	@Override
	public void setTakenCropedBitmap(Bitmap bm) {
		cameraTakenBitmap = bm;
		invalidate();
	}

}
